package com.neusoft.weekreport.component.controller;

import com.neusoft.weekreport.component.bizService.DayBizService;
import com.neusoft.weekreport.component.req.*;
import com.neusoft.weekreport.component.resp.GetDayDetailInfoResp;
import com.neusoft.weekreport.component.req.GetAddDayDetailReq;
import com.neusoft.weekreport.component.resp.ResponseBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author 张峰伟
 * @Create 2020/2/15 16:21
 */

@RestController
@EnableTransactionManagement
@RequestMapping("/day")
public class DayController {

    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    DayBizService dayBizService;

    //保存日报
    @RequestMapping(value="/saveDayDetail",method = RequestMethod.POST)
    public ResponseBean saveDayDetailList(@RequestBody GetAddProductWorkReq req, HttpServletRequest request) {
        ResponseBean responseBean = new ResponseBean<>();
        try{
            dayBizService.saveDayDetailList(req);
            responseBean = new ResponseBean(HttpStatus.OK.value(),"添加日报失败",responseBean);
        }catch (Exception e){
            responseBean.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
            responseBean.setMsg(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
            logger.error(e.toString());
        }
        return responseBean;
    }

    //添加日报
    @RequestMapping(value="/addDayDetail",method = RequestMethod.POST)
    public ResponseBean addDayDetailList(@RequestBody GetAddProductWorkReq req, HttpServletRequest request) {
        ResponseBean responseBean = new ResponseBean<>();
        try{
            dayBizService.addDayDetailList(req);
            responseBean = new ResponseBean(HttpStatus.OK.value(),"添加日报失败",responseBean);
        }catch (Exception e){
            responseBean.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
            responseBean.setMsg(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
            logger.error(e.toString());
        }
        return responseBean;
    }

    //查询日报
    @RequestMapping(value = "/dayDetailManage",method = RequestMethod.POST)
    public ResponseBean<GetDayDetailInfoResp> getDayDetailInfo(@RequestBody GetDayDetailReq req,HttpServletRequest request){
        ResponseBean<GetDayDetailInfoResp> responseBean = new ResponseBean<>();
        try{
            GetDayDetailInfoResp resp = dayBizService.getDayDetailInfo(req);
            responseBean = new ResponseBean(HttpStatus.OK.value(),"查询日报成功",resp);
        }catch(Exception e){
            responseBean.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
            responseBean.setMsg(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
            logger.error(e.toString());
        }
        return responseBean;
    }

    //删除日报
    @RequestMapping(value = "/dayDetailManage",method = RequestMethod.DELETE)
    public ResponseBean deleteDayInfo(@RequestBody GetDeleteDayReq req,HttpServletRequest request){
        ResponseBean responseBean = new ResponseBean();
        try{
            dayBizService.deleteDayInfo(req);
            responseBean = new ResponseBean(HttpStatus.OK.value(),"查询日报成功",responseBean);
        }catch(Exception e){
            responseBean.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
            responseBean.setMsg(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
            logger.error(e.toString());
        }
        return responseBean;
    }


}

